package cn.bugstack.mybatis.scripting.defaults;

import cn.bugstack.mybatis.mapping.BoundSql;
import cn.bugstack.mybatis.mapping.ParameterMapping;
import cn.bugstack.mybatis.mapping.SqlSource;
import cn.bugstack.mybatis.session.Configuration;
import cn.bugstack.mybatis.type.JdbcType;
import org.apache.ibatis.parsing.GenericTokenParser;
import org.apache.ibatis.parsing.TokenHandler;

import java.util.ArrayList;
import java.util.List;

public class StaticSqlSource implements SqlSource {

    private  String sql;
    private  List<ParameterMapping> parameterMappings;
    private  Configuration configuration;

    public StaticSqlSource(String sql) {
        this.sql = sql;
    }

    public StaticSqlSource(String sql, List<ParameterMapping> parameterMappings, Configuration configuration) {
        this.sql = sql;
        this.parameterMappings = parameterMappings;
        this.configuration = configuration;
    }

    @Override
    public BoundSql getBoundSql(Object parameterObject) {

        // 返回静态 SQL
        // 替换 #{}
        // 获取参数
        return new BoundSql.Builder()
                .configuration(configuration)
                .sql(sql)
                .parameterMapping(parameterMappings)
                .parameterObject(parameterObject)
                .build();
    }


}
